extends NodeState


var player: Player:
	get:
		return state_matchine.root as Player

# 冲刺持续的时间
var _duration: float
# 冲刺方向
var _dash_direction: Vector2


func _on_enter(_data: NodeStateData) -> void:
	_duration = 0.0
	_dash_direction = player.input_manager.movment_direction
	player._last_dash_time = Time.get_ticks_msec()
	player.modulate.a = 0.5
	player.collision_shape.set_deferred("disabled", false)
	player.animation_player.play(Player.ANIMATION_DASH)
	# 拖尾效果
	player.tail.start_tail()


func _on_exit() -> void:
	player.modulate.a = 1.0
	player.collision_shape.set_deferred("disabled", true)
	player.tail.stop_tail()


func _on_process(delta : float) -> void:
	if not player.input_manager.is_move_pressed():
		transition_state(Player.STATE_IDLE)
		return
	if _duration >= player.dash_duration:
		transition_state(Player.STATE_MOVE)
		return
	_duration += delta

	player.change_position(_dash_direction * delta * player.stats.speed * player.dash_speed_multi)
	player.flip_sprite()
